-- copy_attrib
-- create by chendh
-- 复制属性

return {
    apply = function(source, target, skillId, round, para, value)
        local disableProp = SkyPropM.getFighterProp(target, "disable_prop");
        if disableProp["copy_attrib"] then
            -- 对方有无法复制属性的符石效果，则四维改为20
            for _, attrib in ipairs(para) do
                source.dbase:set(attrib, 30);
            end

            -- 免疫了
            return { ["damage"] = 0, ["cure"] = 0, };
        end

        local function changeList(attrib)
            if attrib == "hp" then
                return ({ "hp", });
            else
                return ({
                    attrib,
                    "sky_prop/base_attrib/" .. attrib,
                    "sky_prop/permillage_attrib/" .. attrib,
                    "sky_prop/defenser_attrib/" .. attrib,
                    "sky_prop/defenser_permillage_attrib/" .. attrib,
                });
            end
        end

        local  attrib, path;
        for _, attrib in ipairs(para) do

            if table.indexOf({ "fire", "armor", "speed", "luck", "fight_ability", "hp"}, attrib) < 0 then
                return;
            end

            -- 因为战斗对象的四维和战斗等属性涉及到固定数值和百分比计算
            -- 因此这里不能直接进行固定值修改
            -- 复制所有需要复制的属性
            for _, path in ipairs(changeList(attrib)) do
                source.dbase:setEx(path, target.dbase:queryEx(path));
            end
        end

        -- 0伤害
        return { ["damage"] = 0, ["cure"] = 0, };
    end,

    parse = function(desc)
        local arr = string.explode(desc, ",");
        return arr;
    end,

    getDetail = function(para)
        -- 直接取prop描述
        return PropM.getPropDesc(para);
    end,

    getShipgunDetail = function(para, rate)
        -- 飞艇主炮描述
        local desc = getLocStr("shipskill_debuff");
        local alias = PropM.getPropAlias(para[1]);

        return string.format(desc, rate, alias);
    end,

    parseDesc = function(desc, para)
        -- 回合，每次替换一个
        return string.gsub(desc, "{round}", para[4], 1);
    end,
};
